const fs = require('fs');
const path = require('path');

// 读取Home.vue文件
const filePath = path.join(__dirname, 'homework-master/chat-ai-system-backup/frontend/src/views/Home.vue');
const content = fs.readFileSync(filePath, 'utf8');

// 提取script标签内容
const scriptMatch = content.match(/<script[^>]*>([\s\S]*?)<\/script>/);
if (scriptMatch) {
    const scriptContent = scriptMatch[1];
    
    // 简单的括号计数检查
    let openBrackets = 0;
    let closeBrackets = 0;
    let lastOpenLine = 0;
    let lastCloseLine = 0;
    
    const lines = scriptContent.split('\n');
    
    lines.forEach((line, index) => {
        const lineNum = index + 1;
        
        // 计算该行的开括号
        const opens = (line.match(/\{/g) || []).length;
        // 计算该行的闭括号
        const closes = (line.match(/\}/g) || []).length;
        
        openBrackets += opens;
        closeBrackets += closes;
        
        if (opens > 0) lastOpenLine = lineNum;
        if (closes > 0) lastCloseLine = lineNum;
        
        // 输出每行的括号情况
        console.log(`Line ${lineNum}: ${opens} opens, ${closes} closes, balance: ${openBrackets - closeBrackets}`);
        
        // 如果有语法错误，显示当前行
        if (line.includes('};')) {
            console.log(`WARNING: Line ${lineNum} contains };`);
        }
    });
    
    console.log(`\nSummary: ${openBrackets} open brackets, ${closeBrackets} close brackets, difference: ${openBrackets - closeBrackets}`);
    console.log(`Last open bracket at line ${lastOpenLine}`);
    console.log(`Last close bracket at line ${lastCloseLine}`);
    
    // 显示最后几个方法
    console.log('\nLast 20 lines of script content:');
    console.log(lines.slice(-20).join('\n'));
    
} else {
    console.log('No script tag found');
}